<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Multi-head Support Overview</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
<link rel="home" href="index.html" title="GDK 2 Reference Manual">
<link rel="up" href="reference.html" title="API Reference">
<link rel="prev" href="gdk-General.html" title="General">
<link rel="next" href="GdkDisplay.html" title="GdkDisplay">
<meta name="generator" content="GTK-Doc V1.18 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle">
<td><a accesskey="p" href="gdk-General.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
<td><a accesskey="u" href="reference.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
<th width="100%" align="center">GDK 2 Reference Manual</th>
<td><a accesskey="n" href="GdkDisplay.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
</tr></table>
<div class="refentry">
<a name="multihead"></a><div class="titlepage"></div>
<div class="refnamediv"><table width="100%"><tr>
<td valign="top">
<h2><span class="refentrytitle">Multi-head Support Overview</span></h2>
<p>Multi-head Support Overview — Overview of GdkDisplay and GdkScreen</p>
</td>
<td valign="top" align="right"></td>
</tr></table></div>
<div class="refsect1">
<a name="id602142"></a><h2>Overview</h2>
<p>
	Multihead support is based around two main object types:
	</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem"><p>GdkDisplay</p></li>
<li class="listitem"><p>GdkScreen</p></li>
</ul></div>
<p>
      </p>
<p>
	GdkDisplay objects are the GDK
	representation of the X Display which can be described as <span class="emphasis"><em>a
	workstation consisting of a keyboard a pointing device (such as a
	  mouse) and one or more screens</em></span>. 
	It is used to open and keep track of various GdkScreen objects currently 
	instanciated by the application. It is also used to grab and release
	the keyboard and the mouse pointer.
      </p>
<p>
	GdkScreen objects are the GDK
	representation of a physical screen. It is used throughout GDK and GTK+
	to specify which screen the top level windows are to be displayed on. 
	It is also used to query the screen specification and default settings such as 
	the default colormap (<a class="link" href="GdkScreen.html#gdk-screen-get-default-colormap" title="gdk_screen_get_default_colormap ()">gdk_screen_get_default_colormap</a>()),
	the screen width (<a class="link" href="GdkScreen.html#gdk-screen-get-width" title="gdk_screen_get_width ()">gdk_screen_get_width</a>()), etc.
      </p>
<p> 
	The following code samples demonstrate common usage of the objects described above.
      </p>
<div class="example">
<a name="id611149"></a><p class="title"><b>Example 2. Testing the number of screen on the current display</b></p>
<div class="example-contents">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="usertype">gint</span><span class="normal"> num_screen </span><span class="symbol">=</span><span class="normal"> </span><span class="number">0</span><span class="symbol">;</span>
<span class="usertype">gchar</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">displayname </span><span class="symbol">=</span><span class="normal"> <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">;</span>
<span class="usertype">GdkScreen</span><span class="normal"> </span><span class="symbol">**</span><span class="normal">screen_list</span><span class="symbol">;</span>
<span class="usertype">GdkDisplay</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">display</span><span class="symbol">;</span>

<span class="function"><a href="http://library.gnome.org/devel/gtk/gtk3-General.html#gtk-init">gtk_init</a></span><span class="normal"> </span><span class="symbol">(&amp;</span><span class="normal">argc</span><span class="symbol">,</span><span class="normal"> </span><span class="symbol">&amp;</span><span class="normal">argv</span><span class="symbol">);</span>

<span class="normal">display </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="GdkDisplay.html#gdk-display-get-default">gdk_display_get_default</a></span><span class="normal"> </span><span class="symbol">();</span>
<span class="normal">num_screen </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="GdkDisplay.html#gdk-display-get-n-screens">gdk_display_get_n_screens</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">display</span><span class="symbol">);</span>
<span class="normal">displayname </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="GdkDisplay.html#gdk-display-get-name">gdk_display_get_name</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">display</span><span class="symbol">);</span>
<span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">num_screen </span><span class="symbol">&lt;=</span><span class="normal"> </span><span class="number">1</span><span class="symbol">)</span>
<span class="normal">  </span><span class="cbracket">{</span>
<span class="normal">    </span><span class="function">printf</span><span class="normal"> </span><span class="symbol">(</span><span class="string">"This Xserver (%s) manages only one screen. exiting...</span><span class="specialchar">\n</span><span class="string">"</span><span class="symbol">,</span>
<span class="normal">            displayname</span><span class="symbol">);</span>
<span class="normal">    </span><span class="function">exit</span><span class="normal"> </span><span class="symbol">(</span><span class="number">1</span><span class="symbol">);</span>
<span class="normal">  </span><span class="cbracket">}</span>
<span class="keyword">else</span>
<span class="normal">  </span><span class="cbracket">{</span>
<span class="normal">    </span><span class="function">printf</span><span class="normal"> </span><span class="symbol">(</span><span class="string">"This Xserver (%s) manages %d screens.</span><span class="specialchar">\n</span><span class="string">"</span><span class="symbol">,</span><span class="normal"> displayname</span><span class="symbol">,</span>
<span class="normal">            num_screen</span><span class="symbol">);</span>
<span class="normal">  </span><span class="cbracket">}</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

</div>
<br class="example-break"><div class="example">
<a name="id606099"></a><p class="title"><b>Example 3. Opening a second display</b></p>
<div class="example-contents">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="usertype">gchar</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">second_screen_name</span><span class="symbol">;</span>
<span class="usertype">GdkDisplay</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">second_display</span><span class="symbol">;</span>
<span class="usertype">GdkScreen</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">second_screen</span><span class="symbol">;</span>
<span class="usertype">GtkWidget</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">window</span><span class="symbol">;</span>

<span class="function"><a href="http://library.gnome.org/devel/gtk/gtk3-General.html#gtk-init">gtk_init</a></span><span class="normal"> </span><span class="symbol">(&amp;</span><span class="normal">argc</span><span class="symbol">,</span><span class="normal"> </span><span class="symbol">&amp;</span><span class="normal">argv</span><span class="symbol">);</span>

<span class="comment">/* screen2_name needs to be initialized before calling </span>
<span class="comment">/* gdk_display_new() */</span>
<span class="normal">second_display </span><span class="symbol">=</span><span class="normal"> </span><span class="function">gdk_display_new</span><span class="normal"> </span><span class="symbol">(&amp;</span><span class="normal">argc</span><span class="symbol">,</span><span class="normal"> </span><span class="symbol">&amp;</span><span class="normal">argv</span><span class="symbol">,</span><span class="normal"> second_screen_name</span><span class="symbol">);</span>
<span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">second_display</span><span class="symbol">)</span>
<span class="normal">    second_screen </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="GdkDisplay.html#gdk-display-get-default-screen">gdk_display_get_default_screen</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">second_display</span><span class="symbol">);</span>
<span class="keyword">else</span><span class="normal"> </span>
<span class="normal">  </span><span class="cbracket">{</span>
<span class="normal">    </span><span class="function"><a href="http://library.gnome.org/devel/glib/unstable/glib-Warnings-and-Assertions.html#g-print">g_print</a></span><span class="normal"> </span><span class="symbol">(</span><span class="string">"Can't open display :</span><span class="specialchar">\n\t</span><span class="string">%s</span><span class="specialchar">\n\n</span><span class="string">"</span><span class="symbol">,</span>
<span class="normal">          second_screen_name</span><span class="symbol">);</span>
<span class="normal">    </span><span class="function">exit</span><span class="normal"> </span><span class="symbol">(</span><span class="number">1</span><span class="symbol">);</span><span class="normal">   </span>
<span class="normal">  </span><span class="cbracket">}</span>
<span class="comment">/* now GdkScreen can be assigned to GtkWindows */</span>

<span class="normal">window </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="http://library.gnome.org/devel/gtk/GtkWindow.html#gtk-window-new">gtk_window_new</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal"><a href="http://library.gnome.org/devel/gtk/gtk3-Standard-Enumerations.html#GTK-WINDOW-TOPLEVEL:CAPS">GTK_WINDOW_TOPLEVEL</a></span><span class="symbol">);</span>
<span class="function"><a href="http://library.gnome.org/devel/gtk/GtkWindow.html#gtk-window-set-screen">gtk_window_set_screen</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">window</span><span class="symbol">,</span><span class="normal"> second_screen</span><span class="symbol">);</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

</div>
<br class="example-break">
</div>
<div class="refsect1">
<a name="id632852"></a><h2>See Also</h2>
<p>
	</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term">GdkDisplay</span></p></td>
<td><p>the GDK Object used to represent and manipulate display
		related data</p></td>
</tr>
<tr>
<td><p><span class="term">GdkScreen</span></p></td>
<td><p>the GDK Object used to represent and query screen related
		data</p></td>
</tr>
</tbody>
</table></div>
<p>
      </p>
</div>
</div>
<div class="footer">
<hr>
          Generated by GTK-Doc V1.18</div>
</body>
</html>